public class MaxAliveYear {
    public int maxAliveYear(int[] birth, int[] death) {
        // 差分数组 出生年份年份都在1900·2000之间
        int[] diff = new int[102];
        for (int i = 0; i < birth.length; i++) {
            diff[birth[i] - 1900]++;
            diff[death[i] - 1900 + 1]--;
        }
        int cur = 0;
        int max = 0;
        int year = 0;
        for (int i = 0; i < diff.length; i++) {
            cur += diff[i];
            if (cur > max) {
                max = cur;
                year = i;
            }
        }
        return year + 1900;
    }
    public static void main(String[] args) {
        int[] birth = {1900, 1901, 1950};
        int[] death = {1948, 1951, 2000};
        System.out.println(new MaxAliveYear().maxAliveYear(birth, death));
    }
}